//
//  LSZRequestData.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/8/13.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZRequestData.h"

@implementation LSZRequestData
 
#pragma mark - 上传文件
+(void)UploadFile:(NSString *)file imageView:(UIImage *)imageViewStr :(HTTPString)block
{
    NSString * url = [NSString stringWithFormat:@"%@%@",URLTotal,@"/upload"];
   AFHTTPSessionManager * _manager = [AFHTTPSessionManager manager] ;
    _manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/html",@"image/jpeg",@"image/png",@"image/jpg",@"application/octet-stream",@"text/json",nil] ;
    _manager.requestSerializer  = [AFHTTPRequestSerializer serializer ] ;
    _manager.responseSerializer = [AFHTTPResponseSerializer serializer] ;
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *result = NullStringjudgment([defaults objectForKey:@"token"]);
    [_manager.requestSerializer setValue:result forHTTPHeaderField:@"Auth-Token"];
    [_manager POST:url parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData)
     {
         NSString *fileName = [NSString stringWithFormat:@"%@",file] ;
         //压缩图片
         //_imageEdit是从相机获取的图片
         NSData *imageData = UIImageJPEGRepresentation(imageViewStr, 0.2) ;
         //上传图片到服务器
         [formData appendPartWithFileData:imageData name:@"file" fileName:[fileName lastPathComponent] mimeType:@"image/jpg"];
     }
     //上传过程中调用
          progress:^(NSProgress * _Nonnull uploadProgress)
     {
     }
     //上传成功调用
           success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject)
     {
         NSString *result =[[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];

         block(YES,@"上传成功!",result);
     }
           failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error)
     {
         block(NO,@"上传失败!",nil);
     }] ;
}
#pragma mark - 把头像url上传服务器
+(void)initWithUploadTheAvatarUrlToTheServer:(NSString *)stirng :(HTTPString)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:stirng,@"headUrl", nil];
    NSString * string = [NSString stringWithFormat:@"%@",@"/customer/_put/head/"];
    [LSZTotalRequest initWithPostNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
        if (isOk == YES) {
            block(YES,@"",diction);
        }else{
            block(NO,string,nil);
        }
    }];
}
//#pragma mark - 提交问题
//+(void)submitQuestions:(NSString *)content :(HTTPDic)block
//{
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:content,@"content", nil];
//    NSString * string = [NSString stringWithFormat:@"%@",@"/question/content"];
//    [LSZTotalRequest initWithPostNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
//        if (isOk == YES) {
//            block(YES,@"",diction);
//        }else{
//            block(NO,string,nil);
//        }
//    }];
//}
//#pragma mark - 获取本人所在机构/单位 branch/self
//+(void)getMyOrganization:(HTTPDic)block
//{
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
//    NSString * string = [NSString stringWithFormat:@"%@",@"/branch/self"];
//    [LSZTotalRequest initWithGetNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
//        if (isOk == YES) {
//            [_UserM setLeaf:NullStringjudgment(NSStr(diction[@"leaf"]))];
//            [_UserM setId_id:NullStringjudgment(NSStr(diction[@"id"]))];
//            [_UserM setName:NullStringjudgment(NSStr(diction[@"name"]))];
//            [_UserM setSummary:NullStringjudgment(NSStr(diction[@"summary"]))];
//            block(YES,@"",diction);
//        }else{
//            block(NO,string,nil);
//        }
//    }];
//}
//#pragma mark - 个人中心
//+(void)initWithPersonalCenter:(HTTPDic)block
//{
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
//    NSString * string = [NSString stringWithFormat:@"%@",@"/customer/self"];
//    [LSZTotalRequest initWithGetNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
//        if (isOk == YES) {
//            [_MyCenter setMy_id:NullStringjudgment(NSStr(diction[@"id"]))];
//            [_MyCenter setRealName:NullStringjudgment(NSStr(diction[@"realName"]))];
//            [_MyCenter setMobilePhone:NullStringjudgment(NSStr(diction[@"mobilePhone"]))];
//            [_MyCenter setBranch_name:NullStringjudgment(NSStr(diction[@"branch"][@"name"]))];
//            [_MyCenter setBranch_id:NullStringjudgment(NSStr(diction[@"branch"][@"id"]))];
//            [_MyCenter setSex:NullStringjudgment(NSStr(diction[@"sex"]))];
//            [_MyCenter setDepartmentScore:NullStringjudgment(NSStr(diction[@"branch"][@"score"]))];
//            [_MyCenter setHeadUrl:[NSString stringWithFormat:@"%@%@",URLTotal,diction[@"headUrl"]]];
//            [_MyCenter setMy_summary:NullStringjudgment(NSStr(diction[@"branch"][@"summary"]))];
//            if ([[diction allKeys] containsObject:@"account"]) {
//                NSDictionary * dic = diction[@"account"];
//                if ([[dic allKeys] containsObject:@"role"]) {
//                    id role = dic[@"role"];
//                    if ([role isKindOfClass:[NSDictionary class]]) {
//                        [_MyCenter setRoleId:role[@"id"]];
//                    }
//                }
//            }
//            block(YES,@"",diction);
//        }else{
//            block(NO,string,nil);
//        }
//    }];
//}
//#pragma mark - 获取大数据_党员人数
//+(void)initWithTheNumberParty :(HTTPString)block
//{
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
//    NSString * string = [NSString stringWithFormat:@"%@",@"/customer/total"];
//    [LSZTotalRequest initWithGetNoEncryptionRequestReturnStr:string :dic :^(BOOL isOk, NSString * string, id diction) {
//        if (isOk == YES) {
//            block(YES,@"",diction);
//        }else{
//            block(NO,string,nil);
//        }
//    }];
//}
//#pragma mark - 获取大数据_支部人数
//+(void)initWithThenumberBranch :(HTTPString)block
//{
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
//    NSString * string = [NSString stringWithFormat:@"%@",@"/branch/leaf/total"];
//    [LSZTotalRequest initWithGetNoEncryptionRequestReturnStr:string :dic :^(BOOL isOk, NSString * string, id diction) {
//        if (isOk == YES) {
//            block(YES,@"",diction);
//        }else{
//            block(NO,string,nil);
//        }
//    }];
//}
//#pragma mark - 获取大数据_12个月的学习情况
//+(void)initWithTheLearningSituation :(HTTPString)block
//{
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
//    NSString * string = [NSString stringWithFormat:@"%@",@"/activity/12months"];
//    [LSZTotalRequest initWithGetNoEncryptionRequestReturnStr:string :dic :^(BOOL isOk, NSString * string, id diction) {
//        if (isOk == YES) {
//            block(YES,@"",diction);
//        }else{
//            block(NO,string,nil);
//        }
//    }];
//}
//#pragma mark - 修改性别
//+(void)initWithModifyTheGender:(NSString *)gender :(HTTPString)block
//{
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:gender,@"sex", nil];
//    NSString * string = [NSString stringWithFormat:@"%@",@"/customer/_put"];
//    [LSZTotalRequest initWithGetNoEncryptionRequestReturnStr:string :dic :^(BOOL isOk, NSString * string, id diction) {
//        if (isOk == YES) {
//            block(YES,@"",diction);
//        }else{
//            block(NO,string,nil);
//        }
//    }];
//}
//#pragma mark- 删除收藏
//+(void)initWithDeleteTheCollection:(NSString *)id_id :(HTTPString)block
//{
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
//    NSString * string = [NSString stringWithFormat:@"%@%@",@"/article/history/_del/favor/",id_id];
//    [LSZTotalRequest initWithPostNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
//        if (isOk == YES) {
//            block(YES,@"",diction);
//        }else{
//            block(NO,string,nil);
//        }
//    }];
//}
//#pragma mark - 收藏
//+(void)initTheArticleCollects:(NSString *)id_id :(HTTPDic)block
//{
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
//    NSString * string = [NSString stringWithFormat:@"%@%@",@"/article/history/favor/",id_id];
//    [LSZTotalRequest initWithPostNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
//        if (isOk == YES) {
//            block(YES,@"",diction);
//        }else{
//            block(NO,string,nil);
//        }
//    }];
//}
//#pragma mark - 满60分提交数据
//+(void)initWithPassTheData :(NSString *)paperId :(NSString *)mark :(HTTPDic)block
//{
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:mark,@"mark", nil];
//    NSString * string = [NSString stringWithFormat:@"%@%@",@"/exam/result/",paperId];
//    [LSZTotalRequest initWithPostNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
//        if (isOk == YES) {
//            block(YES,@"",diction);
//        }else{
//            block(NO,string,nil);
//        }
//    }];
//}
//#pragma mark - 对问题进行答复
//+(void)initWithAnswerQuestions :(NSString *)paperId  content:(NSString*)content :(HTTPDic)block
//{
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:content,@"content", nil];
//    NSString * string = [NSString stringWithFormat:@"%@%@",@"/answer/content/",paperId];
//    [LSZTotalRequest initWithPostNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
//        if (isOk == YES) {
//            block(YES,@"",diction);
//        }else{
//            block(NO,string,nil);
//        }
//    }];
//}
//#pragma mark - 修改密码
//+(void)initWithChangeThePassword:(NSString *)oldPassword :(NSString *)newPassword :(HTTPString)block
//{
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:oldPassword,@"oldPassword",newPassword,@"newPassword", nil];
//    NSString * string = [NSString stringWithFormat:@"%@",@"/customer/_put/password"];
//    [LSZTotalRequest initWithPostNoEncryptionRequestReturnStr:string :dic :^(BOOL isOk, NSString * string, id str) {
//        if(isOk == YES){
//            NSString * String = NullStringjudgment(NSStr(str));
//            if(String.length > 0){
//                NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//                [defaults setObject:str forKey:@"token"];
//                [defaults synchronize];
//                block(YES,string,str);
//            }else{
//                block(NO,@"原密码输入有问题,请重试!",str);
//            }
//        }else{
//            block(NO,string,nil);
//        }
//    }];
//}
//#pragma mark - 删除三会一课
//+(void)initWithDeleteThreeSessionsLesson:(NSString *)id_id :(HTTPString)block
//{
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
//    NSString * string = [NSString stringWithFormat:@"%@%@%@",@"/activity/_del/",id_id,@"/self"];
//    [LSZTotalRequest initWithPostNoEncryptionRequestReturnStr:string :dic :^(BOOL isOk, NSString * str, id Str) {
//        if (isOk == YES) {
//            block(YES,string,str);
//        }else{
//            block(NO,string,nil);
//        }
//    }];
//}
//#pragma mark - 发布三会一课
//+(void)initWithPublishThreeMeetingsOneLesson:(NSString *)subject activityTime:(NSString *)activityTime address:(NSString *)address personNames:(NSString *)personNames content:(NSString *)content coverUrl:(NSString *)coverUrl id_id:(NSString *)id_id :(HTTPString)block
//{
//    NSDictionary * dicId =  [[NSDictionary alloc]initWithObjectsAndKeys:id_id,@"id", nil];
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:subject,@"subject",activityTime,@"activityTime",address,@"address",personNames,@"personNames",content,@"content",coverUrl,@"coverUrl",dicId,@"catalog", nil];
//    [LSZTotalRequest initWithPostNoEncryptionRequestThreeLesson:@"/activity" :dic :^(BOOL isOK, NSString * string, id dic) {
//        if (isOK == YES) {
//            block(YES,string,nil);
//        }else{
//            block(NO,string,nil);
//        }
//    }];
//}
//#pragma mark - 互助自己的问题点击变成已解决
//+(void)theProblemMutualAssistanceBecomeSolved:(NSString *)id_id :(HTTPString)block
//{
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
//    NSString * string = [NSString stringWithFormat:@"%@%@%@",@"/question/_put/",id_id,@"/solved"];
//    [LSZTotalRequest initWithPostNoEncryptionRequestReturnStr:string :dic :^(BOOL isOk, NSString * str, id Str) {
//        if (isOk == YES) {
//            block(YES,str,Str);
//        }else{
//            block(NO,str,nil);
//        }
//    }];
//}
//#pragma mark - 互助删除自己发布的问题
//+(void)mutualDeletionTheirOwnIssues:(NSString *)id_id :(HTTPString)block
//{
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
//    NSString * string = [NSString stringWithFormat:@"%@%@%@",@"/question/_del/",id_id,@"/self"];
//    [LSZTotalRequest initWithPostNoEncryptionRequestReturnStr:string :dic :^(BOOL isOk, NSString * str, id Str) {
//        if (isOk == YES) {
//            block(YES,str,Str);
//        }else{
//            block(NO,str,nil);
//        }
//    }];
//}
//#pragma mark - 文章看 向后台记录
//+(void)completeDocumentation:(NSString *)period paperId:(NSString *)paperId :(HTTPString)block
//{
//    NSString * strUrl = [[NSString alloc]init];
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
//    if ([period isEqualToString:@"0"]) {
//        //资讯
//        strUrl = [NSString stringWithFormat:@"/article/history/%@",paperId];
//    }else{
//        dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:period,@"period", nil];
//        strUrl = [NSString stringWithFormat:@"/chapter/record/%@",paperId];
//    }
//    [LSZTotalRequest initWithPostNoEncryptionRequestReturnStr:strUrl :dic :^(BOOL isOk, NSString * str, id Str) {
//        if (isOk == YES) {
//            block(YES,str,Str);
//        }else{
//            block(NO,str,nil);
//        }
//    }];
//}
//#pragma mark- 音视频完成90秒
//+(void)WatchAudioAndVideoFinished:(NSString *)period paperId:(NSString *)paperId :(HTTPString)block
//{
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:period,@"period", nil];
//    NSString * strUrl = [NSString stringWithFormat:@"/chapter/record/%@",paperId];;
//    [LSZTotalRequest initWithPostNoEncryptionRequestReturnStr:strUrl :dic :^(BOOL isOk, NSString * str, id Str) {
//        if (isOk == YES) {
//            block(YES,str,Str);
//        }else{
//            block(NO,str,nil);
//        }
//    }];
//}
#pragma mark - 检测版本更新
+(void)detectionVersionUpdate:(HTTPDic)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    NSString * string = [NSString stringWithFormat:@"%@",@"/version/09e3e39c88b34ff68e29e658fe7d41a2"];
    [LSZTotalRequest initWithGetNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
        NSLog(@"%@>>>>>>",diction);
        if (isOk == YES) {
            block(YES,@"",diction);
        }else{
            block(NO,string,nil);
        }
    }];
    //initWithGetNoEncryptionRequest
    //initWithGetNoEncryptionRequestReturnStr
}
@end
